<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>新特性</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="migration56.incompatible.html">« 向后不兼容</a></li>
      <li style="float: right;"><a href="migration56.deprecated.html">PHP 5.6.x 中已废止的特性 »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="migration56.html">从 PHP 5.5.x 移植到 PHP 5.6.x</a></li>
    <li>新特性</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="migration56.new-features" class="sect1">
 <h2 class="title">新特性</h2>

 <div class="sect2" id="migration56.new-features.const-scalar-exprs">
  <h3 class="title">使用表达式定义常量</h3>

  <p class="para">
   在之前的 PHP 版本中，
   必须使用静态值来定义常量，声明属性以及指定函数参数默认值。
   现在你可以使用包括数值、字符串字面量以及其他常量在内的数值表达式来
   定义常量、声明属性以及设置函数参数默认值。
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">const&nbsp;</span><span style="color: #0000BB">ONE&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br />const&nbsp;</span><span style="color: #0000BB">TWO&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ONE&nbsp;</span><span style="color: #007700">*&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">;<br /><br />class&nbsp;</span><span style="color: #0000BB">C&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;</span><span style="color: #0000BB">THREE&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">TWO&nbsp;</span><span style="color: #007700">+&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;</span><span style="color: #0000BB">ONE_THIRD&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ONE&nbsp;</span><span style="color: #007700">/&nbsp;</span><span style="color: #0000BB">self</span><span style="color: #007700">::</span><span style="color: #0000BB">THREE</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;</span><span style="color: #0000BB">SENTENCE&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'The&nbsp;value&nbsp;of&nbsp;THREE&nbsp;is&nbsp;'</span><span style="color: #007700">.</span><span style="color: #0000BB">self</span><span style="color: #007700">::</span><span style="color: #0000BB">THREE</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">f</span><span style="color: #007700">(</span><span style="color: #0000BB">$a&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ONE&nbsp;</span><span style="color: #007700">+&nbsp;</span><span style="color: #0000BB">self</span><span style="color: #007700">::</span><span style="color: #0000BB">THREE</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">$a</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br />echo&nbsp;(new&nbsp;</span><span style="color: #0000BB">C</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">f</span><span style="color: #007700">().</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">C</span><span style="color: #007700">::</span><span style="color: #0000BB">SENTENCE</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <p class="para">以上例程会输出：</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
4
The value of THREE is 3
</pre></div>
   </div>
  </div>

  <p class="para">
   现在可以通过 <code class="literal">const</code> 关键字来定义类型为 <span class="type">array</span> 的常量。
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">const&nbsp;</span><span style="color: #0000BB">ARR&nbsp;</span><span style="color: #007700">=&nbsp;[</span><span style="color: #DD0000">'a'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'b'</span><span style="color: #007700">];<br /><br />echo&nbsp;</span><span style="color: #0000BB">ARR</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">];<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <p class="para">以上例程会输出：</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
a
</pre></div>
   </div>
  </div>
 </div>

 <div class="sect2" id="migration56.new-features.variadics">
  <h3 class="title">使用 <code class="literal">...</code> 运算符定义变长参数函数</h3>

  <p class="para">
   现在可以不依赖 <span class="function"><a href="function.func-get-args.html" class="function">func_get_args()</a></span>，
   使用 <code class="literal">...</code> 运算符
   来实现 <a href="functions.arguments.html#functions.variable-arg-list" class="link">变长参数函数</a>。
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">f</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$opt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">null</span><span style="color: #007700">,&nbsp;...</span><span style="color: #0000BB">$params</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;$params&nbsp;是一个包含了剩余参数的数组<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">'$req:&nbsp;%d;&nbsp;$opt:&nbsp;%d;&nbsp;number&nbsp;of&nbsp;params:&nbsp;%d'</span><span style="color: #007700">.</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$req</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$opt</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">count</span><span style="color: #007700">(</span><span style="color: #0000BB">$params</span><span style="color: #007700">));<br />}<br /><br /></span><span style="color: #0000BB">f</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">f</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">f</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">f</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">f</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <p class="para">以上例程会输出：</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
$req: 1; $opt: 0; number of params: 0
$req: 1; $opt: 2; number of params: 0
$req: 1; $opt: 2; number of params: 1
$req: 1; $opt: 2; number of params: 2
$req: 1; $opt: 2; number of params: 3
</pre></div>
   </div>
  </div>
 </div>

 <div class="sect2" id="migration56.new-features.splat">
  <h3 class="title">使用 <code class="literal">...</code> 运算符进行参数展开</h3>

  <p class="para">
   在调用函数的时候，使用 <code class="literal">...</code> 运算符，
   将 <a href="language.types.array.html" class="link">数组</a> 和 
   <span class="interfacename"><strong class="interfacename">可遍历</strong></span> 对象展开为函数参数。
   在其他编程语言，比如 Ruby中，这被称为连接运算符，。
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">add</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$b</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$c</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">$a&nbsp;</span><span style="color: #007700">+&nbsp;</span><span style="color: #0000BB">$b&nbsp;</span><span style="color: #007700">+&nbsp;</span><span style="color: #0000BB">$c</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">$operators&nbsp;</span><span style="color: #007700">=&nbsp;[</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">];<br />echo&nbsp;</span><span style="color: #0000BB">add</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;...</span><span style="color: #0000BB">$operators</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <p class="para">以上例程会输出：</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
6
</pre></div>
   </div>
  </div>
 </div>

 <div class="sect2" id="migration56.new-features.exponentiation">
  <h3 class="title">使用 <code class="literal">**</code> 进行幂运算</h3>

  <p class="para">
   加入右连接运算符 <code class="literal">**</code> 来进行幂运算。
   同时还支持简写的
   <code class="literal">**=</code> 运算符，表示进行幂运算并赋值。
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"2&nbsp;**&nbsp;3&nbsp;==&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%d\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2&nbsp;</span><span style="color: #007700">**&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"2&nbsp;**&nbsp;3&nbsp;**&nbsp;2&nbsp;==&nbsp;%d\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2&nbsp;</span><span style="color: #007700">**&nbsp;</span><span style="color: #0000BB">3&nbsp;</span><span style="color: #007700">**&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$a&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$a&nbsp;</span><span style="color: #007700">**=&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"a&nbsp;==&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%d\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$a</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  <p class="para">以上例程会输出：</p>
  <div class="example-contents screen">
<div class="cdata"><pre>
2 ** 3 ==      8
2 ** 3 ** 2 == 512
a ==           8
</pre></div>
  </div>
  </div>
 </div>

 <div class="sect2" id="migration56.new-features.use">
  <h3 class="title"><code class="literal">use function</code> 以及 <code class="literal">use const</code></h3>

  <p class="para">
   <a href="language.namespaces.importing.html" class="link"><code class="literal">use</code></a> 运算符
    被进行了扩展以支持在类中导入外部的函数和常量。
    对应的结构为 <code class="literal">use function</code>
    和 <code class="literal">use const</code>。
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">namespace&nbsp;</span><span style="color: #0000BB">Name</span><span style="color: #007700">\</span><span style="color: #0000BB">Space&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;</span><span style="color: #0000BB">FOO&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">42</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;</span><span style="color: #0000BB">f</span><span style="color: #007700">()&nbsp;{&nbsp;echo&nbsp;</span><span style="color: #0000BB">__FUNCTION__</span><span style="color: #007700">.</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;&nbsp;}<br />}<br /><br />namespace&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;use&nbsp;const&nbsp;</span><span style="color: #0000BB">Name</span><span style="color: #007700">\</span><span style="color: #0000BB">Space</span><span style="color: #007700">\</span><span style="color: #0000BB">FOO</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;use&nbsp;function&nbsp;</span><span style="color: #0000BB">Name</span><span style="color: #007700">\</span><span style="color: #0000BB">Space</span><span style="color: #007700">\</span><span style="color: #0000BB">f</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">FOO</span><span style="color: #007700">.</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">f</span><span style="color: #007700">();<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <p class="para">以上例程会输出：</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
42
Name\Space\f
</pre></div>
   </div>
  </div>
 </div>

 <div class="sect2" id="migration56.new-features.phpdbg">
  <h3 class="title">phpdbg</h3>

  <p class="para">
   PHP 的 SAPI 模块中实现了一个
   交互式调试器，叫做 phpdbg。更多信息，请访问
   <a href="book.phpdbg.html" class="link">phpdbg documentation</a>。
  </p>
 </div>

 <div class="sect2" id="migration56.new-features.default-encoding">
  <h3 class="title">默认字符编码</h3>

  <p class="para">
   对于一些字符编码相关的函数，例如 <span class="function"><a href="function.htmlentities.html" class="function">htmlentities()</a></span>，
   <span class="function"><a href="function.html-entity-decode.html" class="function">html_entity_decode()</a></span> 以及 <span class="function"><a href="function.htmlspecialchars.html" class="function">htmlspecialchars()</a></span>
   使用 <a href="ini.core.html#ini.default-charset" class="link">default_charset</a> 
   作为默认字符集。请注意，对于 iconv（现已废弃） 和 mbstring 相关的函数，
   如果分别设置了他们的编码，
   那么这些对应设置的优先级高于 default_charset。
  </p>

  <p class="para">
   default_charset 的默认值是 <code class="literal">UTF-8</code>。
  </p>
 </div>

 <div class="sect2" id="migration56.new-features.reusable-input">
  <h3 class="title"><a href="wrappers.php.html#wrappers.php.input" class="link"><code class="literal">php://input</code></a> 是可重用的了</h3>

  <p class="para">
   只要你需要，你可以多次打开并读取 
   <a href="wrappers.php.html#wrappers.php.input" class="link"><code class="literal">php://input</code></a>。
   同时，这个特性使得在处理 POST 的数据的时候，
   可以明显降低对于内存的需求量。
  </p>
 </div>

 <div class="sect2" id="migration56.new-features.large-file">
  <h3 class="title">大文件上传</h3>

  <p class="para">
   现在可以支持大于 2GB 的文件上传。
  </p>
 </div>

 <div class="sect2" id="migration56.new-features.gmp">
  <h3 class="title"><a href="book.gmp.html" class="link">GMP</a> 支持运算符重载</h3>

  <p class="para">
   <a href="book.gmp.html" class="link">GMP</a> 支持运算符重载，
   并且造型成数值类型。
   这使得使用 GMP 的代码更加直观。
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$a&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">gmp_init</span><span style="color: #007700">(</span><span style="color: #0000BB">42</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$b&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">gmp_init</span><span style="color: #007700">(</span><span style="color: #0000BB">17</span><span style="color: #007700">);<br /><br />if&nbsp;(</span><span style="color: #0000BB">version_compare</span><span style="color: #007700">(</span><span style="color: #0000BB">PHP_VERSION</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'5.6'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'&lt;'</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">gmp_intval</span><span style="color: #007700">(</span><span style="color: #0000BB">gmp_add</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$b</span><span style="color: #007700">)),&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">gmp_intval</span><span style="color: #007700">(</span><span style="color: #0000BB">gmp_add</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">17</span><span style="color: #007700">)),&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">gmp_intval</span><span style="color: #007700">(</span><span style="color: #0000BB">gmp_add</span><span style="color: #007700">(</span><span style="color: #0000BB">42</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$b</span><span style="color: #007700">)),&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$a&nbsp;</span><span style="color: #007700">+&nbsp;</span><span style="color: #0000BB">$b</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$a&nbsp;</span><span style="color: #007700">+&nbsp;</span><span style="color: #0000BB">17</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">42&nbsp;</span><span style="color: #007700">+&nbsp;</span><span style="color: #0000BB">$b</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <p class="para">以上例程会输出：</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
59
59
59
</pre></div>
   </div>
  </div>
 </div>

 <div class="sect2" id="migration56.new-features.hash-equals">
  <h3 class="title">使用 <span class="function"><a href="function.hash-equals.html" class="function">hash_equals()</a></span> 比较字符串避免时序攻击</h3>

  <p class="para">
   加入 <span class="function"><a href="function.hash-equals.html" class="function">hash_equals()</a></span> 函数，
   以恒定的时间消耗来进行字符串比较，
   以避免时序攻击。
   比如当比较 <span class="function"><a href="function.crypt.html" class="function">crypt()</a></span> 密码散列值的时候，就可以使用此函数。
   （假定你不能使用 <span class="function"><a href="function.password-hash.html" class="function">password_hash()</a></span> 和 <span class="function"><a href="function.password-verify.html" class="function">password_verify()</a></span>，
   这两个函数也可以抵抗时序攻击）
  </p>


  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$expected&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">crypt</span><span style="color: #007700">(</span><span style="color: #DD0000">'12345'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'$2a$07$usesomesillystringforsalt$'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$correct&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">crypt</span><span style="color: #007700">(</span><span style="color: #DD0000">'12345'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'$2a$07$usesomesillystringforsalt$'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$incorrect&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">crypt</span><span style="color: #007700">(</span><span style="color: #DD0000">'1234'</span><span style="color: #007700">,&nbsp;&nbsp;</span><span style="color: #DD0000">'$2a$07$usesomesillystringforsalt$'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">hash_equals</span><span style="color: #007700">(</span><span style="color: #0000BB">$expected</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$correct</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">hash_equals</span><span style="color: #007700">(</span><span style="color: #0000BB">$expected</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$incorrect</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <p class="para">以上例程会输出：</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
bool(true)
bool(false)
</pre></div>
   </div>
  </div>
 </div>

 <div class="sect2" id="migration56.new-features.debuginfo">
  <h3 class="title"><code class="literal">__debugInfo()</code></h3>

  <p class="para">
   加入 <a href="language.oop5.magic.html#language.oop5.magic.debuginfo" class="link">__debugInfo()</a>，
   当使用 <span class="function"><a href="function.var-dump.html" class="function">var_dump()</a></span> 输出对象的时候，
   可以用来控制要输出的属性和值。
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">C&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;</span><span style="color: #0000BB">$prop</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">__construct</span><span style="color: #007700">(</span><span style="color: #0000BB">$val</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">prop&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$val</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">__debugInfo</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;[<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'propSquared'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">prop&nbsp;</span><span style="color: #007700">**&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;];<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(new&nbsp;</span><span style="color: #0000BB">C</span><span style="color: #007700">(</span><span style="color: #0000BB">42</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <p class="para">以上例程会输出：</p>
   <div class="example-contents screen">
<div class="cdata"><pre>
object(C)#1 (1) {
  [&quot;propSquared&quot;]=&gt;
  int(1764)
}
</pre></div>
   </div>
  </div>
 </div>

 <div class="sect2" id="migration56.new-features.gost">
  <h3 class="title">gost-crypto 散列算法</h3>

  <p class="para">
   加入 <code class="literal">gost-crypto</code> 散列算法。
   它使用
   <a href="http://www.faqs.org/rfcs/rfc4357" class="link external">&raquo;&nbsp;RFC 4357, 11.2 小节</a> 定义的
   CryptoPro S-box 表实现了 GOST 散列函数。
  </p>
 </div>

 <div class="sect2" id="migration56.new-features.openssl">
  <h3 class="title">SSL/TLS 提升</h3>

  <p class="para">
   在 PHP 5.6 中对 SSL/TLS 的支持进行了大幅度的提升。
   这其中包括
   <a href="migration56.incompatible.html#migration56.incompatible.peer-verification" class="link">默认启用端点验证</a>
   选项来支持证书指纹比对，
   以避免 TLS 重新协商攻击。
   还增加了很多 <a href="context.ssl.html" class="link">SSL 上下文选项</a>，
   以便在使用加密流的时候，
   能够更好的控制协议和验证的相关设置。
  </p>

  <p class="para">
   这些变动在
   <a href="migration56.openssl.html" class="link">PHP 5.6.x 中的 OpenSSL 变更</a>
   中有详细描述。
  </p>
 </div>

 <div class="sect2" id="migration56.new-features.postgresql">
  <h3 class="title"><a href="book.pgsql.html" class="link">pgsql</a> 异步支持</h3>

  <p class="para">
   <a href="book.pgsql.html" class="link">pgsql</a> 扩展现在支持
   异步方式连接数据库及执行查询，
   也即可以使用非阻塞的方式和 PostgreSQL 数据库进行交互。
   使用 <strong><code>PGSQL_CONNECT_ASYNC</code></strong> 常量可以
   建立异步连接，<span class="function"><a href="function.pg-connect-poll.html" class="function">pg_connect_poll()</a></span>，
   <span class="function"><a href="function.pg-socket.html" class="function">pg_socket()</a></span>，
   <span class="function"><a href="function.pg-consume-input.html" class="function">pg_consume_input()</a></span> 和 <span class="function"><a href="function.pg-flush.html" class="function">pg_flush()</a></span> 函数
   可以用来处理异步连接和查询。   
  </p>
 </div>
</div></div></div></body></html>